#ifndef __DISPLAY_H
#define __DISPLAY_H

#include <msp430.h>

// LED:
	// A:	PIN 3.7
	// B:	PIN	3.6
	// C:	PIN	3.5
	// D:	PIN	2.5
	// E:	PIN	2.4
	// F:	PIN	2.3
	// G:	PIN	3.4
	// DP:	PIN	3.3

	// A1:	PIN	2.0
	// A2:	PIN	2.1
	// A3:	PIN	2.2
	// A4:	PIN	3.2

//PORT 2
#define LED_PIN_D	5
#define LED_PIN_E	4
#define LED_PIN_F	3
#define LED_CHOOSE_LED1	0
#define LED_CHOOSE_LED2	1
#define LED_CHOOSE_LED3	2

//PORT 3
#define LED_PIN_A	7
#define LED_PIN_B	6
#define LED_PIN_C	5
#define LED_PIN_G	4
#define LED_PIN_DP	3
#define LED_CHOOSE_LED4	2

#define onLED1()	P2OUT &= ~(1<<0)
#define onLED2()	P2OUT &= ~(1<<1)
#define onLED3()	P2OUT &= ~(1<<2)
#define onLED4()	P3OUT &= ~(1<<2)

#define offLED1()	P2OUT |= (1<<0)
#define offLED2()	P2OUT |= (1<<1)
#define offLED3()	P2OUT |= (1<<2)
#define offLED4()	P3OUT |= (1<<2)

#define	chooseLED1()	onLED1(); offLED2(); offLED3(); offLED4()
#define	chooseLED2()	offLED1(); onLED2(); offLED3(); offLED4()
#define	chooseLED3()	offLED1(); offLED2(); onLED3(); offLED4()
#define	chooseLED4()	offLED1(); offLED2(); offLED3(); onLED4()


#define on_LED_PIN_A	P3OUT |= (1<<7)
#define on_LED_PIN_B	P3OUT |= (1<<6)
#define on_LED_PIN_C	P3OUT |= (1<<5)
#define on_LED_PIN_D	P2OUT |= (1<<5)
#define on_LED_PIN_E	P2OUT |= (1<<4)
#define on_LED_PIN_F	P2OUT |= (1<<3)
#define on_LED_PIN_G	P3OUT |= (1<<4)
#define on_LED_PIN_DP()	chooseLED2();P3OUT |= (1<<3)

#define off_LED_PIN_A	P3OUT &= ~(1<<7)
#define off_LED_PIN_B	P3OUT &= ~(1<<6)
#define off_LED_PIN_C	P3OUT &= ~(1<<5)
#define off_LED_PIN_D	P2OUT &= ~(1<<5)
#define off_LED_PIN_E	P2OUT &= ~(1<<4)
#define off_LED_PIN_F	P2OUT &= ~(1<<3)
#define off_LED_PIN_G	P3OUT &= ~(1<<4)
#define off_LED_PIN_DP()	chooseLED2();P3OUT &= ~(1<<3)

#define display_digit_0()	(on_LED_PIN_A);(on_LED_PIN_B);(on_LED_PIN_C);(on_LED_PIN_D);(on_LED_PIN_E);(on_LED_PIN_F);(off_LED_PIN_G)
#define display_digit_1()	(off_LED_PIN_A);(on_LED_PIN_B);(on_LED_PIN_C);(off_LED_PIN_D);(off_LED_PIN_E);(off_LED_PIN_F);(off_LED_PIN_G)
#define display_digit_2()	(on_LED_PIN_A);(on_LED_PIN_B);(off_LED_PIN_C);(on_LED_PIN_D);(on_LED_PIN_E);(off_LED_PIN_F);(on_LED_PIN_G)
#define display_digit_3()	(on_LED_PIN_A);(on_LED_PIN_B);(on_LED_PIN_C);(on_LED_PIN_D);(off_LED_PIN_E);(off_LED_PIN_F);(on_LED_PIN_G)
#define display_digit_4()	(off_LED_PIN_A);(on_LED_PIN_B);(on_LED_PIN_C);(off_LED_PIN_D);(off_LED_PIN_E);(on_LED_PIN_F);(on_LED_PIN_G)
#define display_digit_5()	(on_LED_PIN_A);(off_LED_PIN_B);(on_LED_PIN_C);(on_LED_PIN_D);(off_LED_PIN_E);(on_LED_PIN_F);(on_LED_PIN_G)
#define display_digit_6()	(on_LED_PIN_A);(off_LED_PIN_B);(on_LED_PIN_C);(on_LED_PIN_D);(on_LED_PIN_E);(on_LED_PIN_F);(on_LED_PIN_G)
#define display_digit_7()	(on_LED_PIN_A);(on_LED_PIN_B);(on_LED_PIN_C);(off_LED_PIN_D);(off_LED_PIN_E);(off_LED_PIN_F);(off_LED_PIN_G)
#define display_digit_8()	(on_LED_PIN_A);(on_LED_PIN_B);(on_LED_PIN_C);(on_LED_PIN_D);(on_LED_PIN_E);(on_LED_PIN_F);(on_LED_PIN_G)
#define display_digit_9()	(on_LED_PIN_A);(on_LED_PIN_B);(on_LED_PIN_C);(on_LED_PIN_D);(off_LED_PIN_E);(on_LED_PIN_F);(on_LED_PIN_G)
#define display_digit_none()	(off_LED_PIN_A);(off_LED_PIN_B);(off_LED_PIN_C);(off_LED_PIN_D);(off_LED_PIN_E);(off_LED_PIN_F);(off_LED_PIN_G)


extern char n[4],pos;

void DispDigit(char *pDigit);
// pChacracter: num digit (0-9)
// pPos: position 1 2 3 4 (left to right)
void DispOneCharOnePos(char *pChar, char pPos);

// pInt: 4-digit num
void DispOneNum(int *pInt);

void DispTwoNum(int *pInt1, int *pInt2);

extern char disp;
void blink_enable(void);
void blink_disable(void);

#endif
